package UnitTest;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;

import java.sql.DriverManager;
import java.sql.PreparedStatement;
import Test.AppBody;
import Test.Course;
import Test.QuestionBody;
import Test.SelectionBody;

import DBModule.CourseTable;
import DBModule.DBManager;
import DBModule.QuestionTable;

import Tool.Tool;

/**
 * 测试用
 * @author prairial
 */
public class Main /*extends Applet*/{
	int a;
	A aa = new A();
	class A{
		int a;
		A (){
			a = 2;
			Main.this.a = 1;
		}
		
		void foo(){
			
			System.out.println(a);
		}
	}
	
	public void foo(){
		aa.foo();
		System.out.println(a);
	}
	
	// 驱动名
	private static String dbDriveName="com.mysql.jdbc.Driver";
	// mysql URL地址
	private static String dbUrl="jdbc:mysql://localhost:3306/Test?user=TestManager&password=123456&characterEncoding=utf-8";
	public static void foo1() throws Exception{
		Class.forName(dbDriveName);
		Connection conn = DriverManager.getConnection(dbUrl);
		conn.setAutoCommit(false);
		PreparedStatement ps = conn.prepareStatement("insert into Teacher_Course values(?, ?)");
		ps.setInt(1, 0);
		ps.setInt(2, 1);
		ps.executeUpdate();
		ps.setInt(1, 1);
		ps.executeUpdate();
		ps.close();
		conn.rollback();
		conn.commit();
		conn.setAutoCommit(true);
		conn.close();
	}
	
	public static String readFromFile(String fn) throws Exception{
		FileInputStream fi = new FileInputStream(fn);
		byte[] buf = new byte[fi.available()];
		fi.read(buf);
		return new String(buf);
	}
	
	static private String head = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><title>你的死期到了</title></head><body>";
	static private String tail = "</body></html>";
	
	public static void foo2() throws Exception{
		Course course = CourseTable.getCourse(2);
		
		QuestionBody qb[] = {
			new SelectionBody(0, course, 3, 1024, "以下哪个不是面向对象的特点", 3, "封装", "继承", "多态", "反射"),
			new SelectionBody(0, course, 3, 1024, "Iterator接口不具备哪个功能", 1, "删除", "添加", "取值", "查询结束"),
			new SelectionBody(0, course, 4, 1024, Tool.toHTML(readFromFile("input.java")), 1, "foo1foo2", "foo1foo3", "foo2foo3", "foo1foo2foo3"),
		};
		QuestionTable.insertAsDefaultID(qb);
	}
	
	public static void main(String args[]) throws Exception{
		Main m = new Main();
		m.foo();
	}
}






